/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2023. All rights reserved.
 * Description: UDK cycles/timer for ARM architecture header file
 * Author: -
 * Create: 2021.4.19
 */

#ifndef UDK_CYCLES_ARM_H
#define UDK_CYCLES_ARM_H

#include <stdint.h>
#include "udk_common.h"

static udk_force_inline uint64_t udk_arm64_cntfrq(void)
{
    uint64_t freq;

    asm volatile("mrs %0, cntfrq_el0" : "=r"(freq));
    return freq;
}

static udk_force_inline uint64_t udk_arm64_cntvct(void)
{
    uint64_t tsc;

    asm volatile("mrs %0, cntvct_el0" : "=r"(tsc));
    return tsc;
}

static udk_force_inline uint64_t udk_rdtsc(void)
{
    return udk_arm64_cntvct();
}

#endif /* UDK_CYCLES_ARM_H */